<template>
  <div>
    <json-view :data="jsonData"/>

    <div class="analysisGeneration-title2">
      <el-button type="warning" @click="readTheDataThatNeedsToBeConfiguredClick">读取需要配置的数据</el-button>
    </div>
    <div class="analysisGeneration-title mt-12">
      <span></span>
      <label>数据配置</label>
      <div class="s"></div>
    </div>
    <div class="mt-12">
      <el-input v-model="propsData.demoDataProp.dataConfiguration" placeholder="请输入解析数据" type="textarea" :autosize="{ minRows: 15, maxRows: 20}" clearable
                class="mr-12 "></el-input>
    </div>
  </div>

</template>

<script>
export default {
  components: {},
  props: ['propsData'],
  data() {
    return {
      jsonData: {
        a: 1
      }
    };
  },
  mounted() {
  },
  methods: {
    //读取需要配置的数据
    readTheDataThatNeedsToBeConfiguredClick() {
      this.propsData.demoDataProp.dataConfiguration = "";
      //分组信息
      let groupNameArray = this.propsData.tableProp.groupNameProp.arrayData.sort(function (p1, p2) { //如果返回负数 p1在前 如果返回正数 p2在前
        return p1.sort - p2.sort
      });
      // 表格内容
      let tableContentArray = this.propsData.tableProp.tableArray.sort(function (p1, p2) { //如果返回负数 p1在前 如果返回正数 p2在前
        return p1.sort - p2.sort
      });
      for (let i = 0; i < groupNameArray.length; i++) {
        for (let j = 0; j < tableContentArray.length; j++) {
          if (groupNameArray[i].label == tableContentArray[j].groupName) {
            if (tableContentArray[j].isArray) {
              groupNameArray[i].isArray = true;//是否是数组
              groupNameArray[i].field = tableContentArray[j].field;//是数组的字段
              groupNameArray[i].name = tableContentArray[j].name;//是数组的名称
            }
          }
        }
      }

      //处理table 里面的字段名称
      let formData = ""
      for (let i = 0; i < groupNameArray.length; i++) {
        if (groupNameArray[i].isArray) {
          let arrayData = `
//${groupNameArray[i].label}值设置
${groupNameArray[i].field}:[
    {`
          //是数组
          for (let j = 0; j < tableContentArray.length; j++) {
            if (groupNameArray[i].label == tableContentArray[j].groupName) {
              if ((tableContentArray[j].drawerSee && tableContentArray[j].drawerEdit) || tableContentArray[j].isArray) {
                continue
              }
              if (['输入框', '密码框', '文本域'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'',//${tableContentArray[j].name}`
              }
              if (['年'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 4)}',//${tableContentArray[j].name}`
              }
              if (['月'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 3)}',//${tableContentArray[j].name}`
              }
              if (['日'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 2)}',//${tableContentArray[j].name}`
              }
              if (['日期和时间'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 1)}',//${tableContentArray[j].name}`
              }
              if (['文件上传', '图片上传'].includes(tableContentArray[j].type)) {
                arrayData += `
      ${tableContentArray[j].field}:'',//${tableContentArray[j].name}`
              }
              if (['多选框', '单选框', '下拉框'].includes(tableContentArray[j].type)) {
                let value = '';
                //处理字段
                if (tableContentArray[j].selectProp.dataSources == '自定义') {
                  let str = `[
                                ${tableContentArray[j].selectProp.text}
                        ]`;
                  let arrayData = eval('(' + str + ')')
                  if (arrayData.length) {
                    value = arrayData[0].value;
                  }
                }
                if (tableContentArray[j].type == '多选框') {
                  arrayData += `
      ${tableContentArray[j].field}:['${value}'],//${tableContentArray[j].name}`
                } else {
                  arrayData += `
      ${tableContentArray[j].field}:'${value}',//${tableContentArray[j].name}`
                }
              }
            }
          }
          formData += `${arrayData}
    },
],
`
        }
        else {
          //不是数组
          for (let j = 0; j < tableContentArray.length; j++) {
            if (groupNameArray[i].label == tableContentArray[j].groupName) {
              if ((tableContentArray[j].drawerSee && tableContentArray[j].drawerEdit)) {
                continue
              }
              if (['输入框', '密码框', '文本域'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'',//${tableContentArray[j].name}`
              }
              if (['年'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 4)}',//${tableContentArray[j].name}`
              }
              if (['月'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 3)}',//${tableContentArray[j].name}`
              }
              if (['日'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 2)}',//${tableContentArray[j].name}`
              }
              if (['日期和时间'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'${this.Utils.currentTime(0, 1)}',//${tableContentArray[j].name}`
              }
              if (['文件上传', '图片上传'].includes(tableContentArray[j].type)) {
                formData += `
    ${tableContentArray[j].field}:'',//${tableContentArray[j].name}`
              }
              if (['多选框', '单选框', '下拉框'].includes(tableContentArray[j].type)) {
                let value = '';
                //处理字段
                if (tableContentArray[j].selectProp.dataSources == '自定义') {
                  let str = `[
                                ${tableContentArray[j].selectProp.text}
                        ]`;
                  let arrayData = eval('(' + str + ')')
                  if (arrayData.length) {
                    value = arrayData[0].value;
                  }
                }
                if (tableContentArray[j].type == '多选框') {
                  formData += `
    ${tableContentArray[j].field}:['${value}'],//${tableContentArray[j].name}`
                } else {
                  formData += `
    ${tableContentArray[j].field}:'${value}',//${tableContentArray[j].name}`
                }
              }
            }
          }
        }
      }
      this.propsData.demoDataProp.dataConfiguration = `{//第1个表格值开始 ${formData}
},//第1个表格值结束`;
    },
  },
};
</script>

<style lang="scss" scoped></style>
